package com.kun.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.kun.dao.ReportDao;
import com.kun.entity.CaseEntity;
@Repository("ReportDaoImpl")
public class ReportDaoImpl implements ReportDao {

	public String addCase(CaseEntity caseEntity) {
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sf = (SessionFactory) app.getBean("sessionFactory");
		Session session = sf.openSession();
		Transaction transaction = session.beginTransaction();
		session.save(caseEntity);
		transaction.commit();
		session.close();
		return "success";
	}

	public List<CaseEntity> findAllCase(String hql, int id) {
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sf = (SessionFactory) app.getBean("sessionFactory");
		Session session = sf.openSession();
		Query query = session.createQuery(hql);
		query.setInteger(0,id);
		List<CaseEntity> list = query.list();
		return list;
	}

}
